import React, {Component} from 'react'
import {connect} from 'react-redux'
import CommentInput from '../component/CommentInput'
import {addComment} from '../action/action'

class CommentInputContainer extends Component{
    handleSubmit(comments){
        if(this.props.onChange){
            this.props.onChange(comments)
        }
    }
    render(){
        return(
            <CommentInput
                onChange={this.handleSubmit.bind(this)}
            />
        )
    }
}
const mapStateToProps = (state) => {
  return {
    comments: state.comments
  }
}
const mapDispatchToProps = (dispatch)=>{
    return {
        onChange:(comments)=>{
            dispatch(addComment(comments))
        }
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(CommentInputContainer)